import {Response} from "express";
import {commonResponse} from "../utils/commonResponse";
import {IPromiseCommonResponse} from "../../global";
import {changeProfileDao} from "../dao/userDao";
import FileMethod from "../utils/fileMethod";

export const changeProfileService = async (res: Response, profile: string | undefined, email: string, oldPath: string) => {
    await commonResponse<IPromiseCommonResponse<{ path: string }>, { path: string }>(res,  async () => {
        oldPath && await FileMethod.fileDel(oldPath)
        await changeProfileDao([profile as string, email])
        return profile ? Promise.resolve({ code: 200, data: { path: profile as string } }) : Promise.resolve({ code: 500, data: { path: '失败' } })
    })
}